package com.bb.blog.activiti.config;

import org.activiti.engine.impl.asyncexecutor.DefaultAsyncJobExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class ActivitiAsyncJobConfig {

    @Bean
    DefaultAsyncJobExecutor defaultAsyncJobExecutor(ExecutorService executorService) {
        DefaultAsyncJobExecutor defaultAsyncJobExecutor = new DefaultAsyncJobExecutor();
        defaultAsyncJobExecutor.setExecutorService(executorService);
        return defaultAsyncJobExecutor;
    }


    @Bean
    ThreadPoolExecutorFactoryBean executorService() {
        ThreadPoolExecutorFactoryBean threadPoolExecutorFactoryBean = new ThreadPoolExecutorFactoryBean();
        threadPoolExecutorFactoryBean.setCorePoolSize(3);
        threadPoolExecutorFactoryBean.setMaxPoolSize(6);
        threadPoolExecutorFactoryBean.setQueueCapacity(10);
        threadPoolExecutorFactoryBean.setThreadNamePrefix("activiti-prefix");
        threadPoolExecutorFactoryBean.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
        return threadPoolExecutorFactoryBean;
    }
}
